package iSms;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;


public class Sms {	

	public static void SendTextMsg(String recNum, String smsContext) {
		PreparedStatement state = null;
		Random generator = new Random();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        
		try {
			Connection conn = ConnectDatabase.getConnection();
			String sql1 = "insert into MBSSendMsg (Sender, Recipient, MsgLevel, MsgType, Subject, URLs, MMSInfo, MsgStatus, MsgSize, RequestTime, SendStyle, SendTime, SendOutTime, DeliverTime, ScreenHeight, ScreenWidth, ComPort, MsgID, RefID, ExtendInfo, Comments) Values ('13260016871', ?, 0, 1, ?, '', '', 0, 8, ?, 0, '', '', '', 200, 140, 0, ?, '', '', '')";
			state = conn.prepareStatement(sql1);
			String msgID = Integer.toString(Math.abs(generator.nextInt()));
			state.setString(1, recNum);
			state.setString(2, smsContext);
			state.setString(3, dateFormat.format(date));
			state.setString(4, msgID);
			state.executeUpdate();
			System.out.println("Sms to " + recNum + "is Waiting, OK");
			state.close();
			conn.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public static void SendMMS(String recNum, String dir, int [] test) {
		PreparedStatement state = null;
		Random generator = new Random();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();

		try {
			Connection conn = ConnectDatabase.getConnection();
			String sql1 = "insert into MBSSendMsg (Sender, Recipient, MsgLevel, MsgType, Subject, URLs, MMSInfo, MsgStatus, MsgSize, RequestTime, SendStyle, SendTime, SendOutTime, DeliverTime, ScreenHeight, ScreenWidth, ComPort, MsgID, RefID, ExtendInfo, Comments) Values ('13581660044', ?, 0, 512, 'route of escape', '', ? , 0, 8000, ?, 0, '', '', '', 200, 140, 0, ?, '', '', '')";
			state = conn.prepareStatement(sql1);
			String msgID = Integer.toString(Math.abs(generator.nextInt()));
			state.setString(1, recNum);
			state.setString(2, dir + Integer.toString(test[0])+Integer.toString(test[1])+".jpg");
			state.setString(3, dateFormat.format(date));
			state.setString(4, msgID);
			state.executeUpdate();
			System.out.println("MMS to " + "is Waiting, OK");
			state.close();
			conn.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

}
